<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">
<title>register </title>
</head>
<body>
<script src="jquery-3.7.0.min.js"></script>

<form action="http://127.0.0.1/index.php?a=login&b=register" method="POST">
	用户名</br>
	<input name='username' value='' id="username">
	</br>密码</br>
	<input name='password' value='' type='password' id='password1'>
	</br>确认密码</br>
	<input name='password2' value='' type='password' id='password2'>
	<p></p>
</form>

<input value='注册' onClick="check_password()" type='submit'>

<script>
	function check_password(p)
	{
		var username = document.getElementById('username').value;
		var p1 = document.getElementById('password1').value;
		var p2 = document.getElementById('password2').value;
		if (p1 != p2)
		{
			return alert('两次输入的密码不一致，请检查')    
		}

		var data = 
		{
			'username':username,
			'password':p1
		};
		$.ajax({
			type:'post',
			url:'./index.php?a=login&b=register',
			data:data,
			dataType:'text',
			success:function(result){
				result = JSON.parse(result)
				console.log(result);
				alert(result.msg);
				if (result.url !='')
				{
					window.location.href = result.url;
				}
			}
		});

	}
</script>

</body>
</html>